$(function() {
	$('.back').on('click', function() {
		window.history.go(-1)
	})
	$('.keep').on('click',function(){
		sendForm($(this),1); 
	});
	$('.rectangle').on('click',function(){
		for(var reidx=0;reidx<$('.rectangle').length;reidx++){
			$('.rectangle').eq(reidx).find('i').removeClass('am-icon-check-square');
			$('.rectangle').eq(reidx).find('i').addClass('am-icon-square-o');
		}
		$(this).find('i').addClass('am-icon-check-square');
		$(this).find('i').removeClass('am-icon-square-o');
		$('.quota').val($(this).data('quota'))
		console.log($('.quota').val())
	});
	{if $Think.get.name||$Think.get.phone}
	{else/}
	$("#loading-first").fadeOut(500);
	{/if}
	$.ajax({
		type: "post",
		url: "{:url('/unit/staff/all')}",
		data: {},
		success: function(res) {
			var list = [];
			var list1 = [];
			var resuit = '';
			//筛选出不是审核员的
			for(var i = 0; i < res.data.length; i++) {
				if(res.data[i].is_check) {

				} else {
					list.push(res.data[i]);
				}
			};
			{if $Think.get.name}
			for(var j = 0; j < list.length; j++) {
				var str = new RegExp("{$Think.get.name}", "i");
				if(list[j].name.match(str)) {
					
				}else{
					list.splice(j,1)
					j--
				}
			}
			{/if}
			{if $Think.get.phone}
			for(var j2 = 0; j2 < list.length; j2++) {
				var str = new RegExp("{$Think.get.phone}", "i");
				if(list[j2].phone.match(str)) {
					
				}else{
					list.splice(j2,1)
					j2--
				}
			}
			
			{/if}
			{if $Think.get.name||$Think.get.phone}
			$("#loading-first").fadeOut(500);
			list1=list
			{/if}
			
			for(var r = 0; r < list1.length; r++) {
				resuit += `<li class="crosswise-li rectangle" data-id='${list1[r].passenger_id}'>
								<span class='app_name'>${list1[r].name}</span>
								&nbsp;${list1[r].phone}&nbsp;
							</li>`;
			}
			$('.search_result').html(resuit);
			pitchon();

			function pitchon() {
				$('.search_result li').unbind();
				$('.search_result li').on('click', function() {
					var limain = `<li class="crosswise-li rectangle"  data-id='${$(this).data('id')}' >
										<div class='am-fl'>${$(this).html()}</div>
										<i class="am-icon-close"></i>
									</li>`;
					var opti = `<option value='${$(this).data('id')}' selected>${$(this).find('.app_name').html()}</option>`;
					limain = `${$('.pitch_on').html()}` + limain;
					opti = `${$('.pitch_select').html()}` + opti;
					$('.pitch_on').html(limain);
					$('.pitch_select').html(opti);
					$(this).remove();
					close();
				});
			};

			function close() {
				$('.pitch_on li .am-icon-close').unbind();
				$('.pitch_on li .am-icon-close').on('click', function() {
					$('.search_result').html(`${$('.search_result').html()}<li class="crosswise-li rectangle">${$(this).parent().find('div').html()}</li>`);
					for(var idx=0;idx<$(this).closest('.pitch').find('option').length;idx++){
						if($(this).closest('.pitch').find('option').eq(idx).val()==$(this).parent().data('id')){
							$(this).closest('.pitch').find('option').eq(idx).remove()
						}
					}
					$(this).parent().remove();
					pitchon();
				})
			}
		}
	})

})